const constans = require('../../constans/constans.js');
const request = require('../../request.js');
const Toast = require('../../utils/Toast.js');
const LogUtils = require('../../utils/LogUtils.js');
const util = require('../../utils/util.js')
const app = getApp();

Page({
  data: {
    logs: [],
    height1: '',
    data: {},
    Count: '00',
    remainCount: '00',
    img:'../../img/wode1_.png',
  },
  onLoad: function () {
    app.requestHeader = { 'Authorization': wx.getStorageSync('Authorization') }

    let that = this;
    // 获取系统信息
    wx.getSystemInfo({
      success: function (res) {
        // 获取可使用窗口宽度
        let clientHeight = res.windowHeight;
        // 获取可使用窗口高度
        let clientWidth = res.windowWidth;
        // 算出比例
        let ratio = 750 / clientWidth;
        // 算出高度(单位rpx)
        let height = clientHeight * ratio;
        // 设置高度
        that.setData({
          height1: height
        });
      }
    });

    fun(that);
  },
  wode:function(){
    wx.navigateTo({
      url: '../wode/wode'
    })
  },
  onShow() {
    let that=this;
    fun(that);
  }

})
function fun(that){
  request.get(
    constans.getActivity,
    { activityId: wx.getStorageSync('activityId'), channel: wx.getStorageSync('channel')},
    function (data) {
      console.log('获取活动');
      wx.setStorageSync('Count', data.data.data.package.count)
      wx.setStorageSync('remainCount', data.data.data.package.count - data.data.data.package.remainCount)
      if (data.data.code == 0) {
        that.setData({
          Count: data.data.data.package.count,
          remainCount: data.data.data.package.count - data.data.data.package.remainCount,
        });
      } else {
        wx.showModal({
          title: '提示',
          showCancel: false,
          content: data.data.message,
        })
      }
    })

  request.get(
    constans.getPackageRecordByPackage,
    { packageId: wx.getStorageSync('packageId') },
    function (data) {

      console.log(data)
      that.setData({
        data: data.data.data,
      });
      //   console.log(that.data.data)
    })
}